package com.zzf.juc练习;



public class  A{
        public static int bh;
    }

     class MyThread extends Thread {

        private int bh;

        public MyThread(String name,int bh){
            super(name);
            this.bh=bh;
        }

        static Object lock = new Object();

        public void run() {
            synchronized (lock){
                A.bh=bh;
            try {Thread.sleep(20);} catch (InterruptedException e) {}
            String sql="select * from where bh="+A.bh;
            System.out.println(this+"-->"+sql);
            }
        }

        public String toString(){
            return "线程[name:"+this.getName()+",bh:"+bh+"]";
        }

        public static void main(String[] args) {
            new MyThread("线程1",5).start();
            new MyThread("线程2",8).start();
            new MyThread("线程2",10).start();
        }

    }


